Skip to content

Fix multipleOf with integer-valued float for large integers - #1459

Open
worksbyfriday wants to merge 1 commit into
python-jsonschema:mainfrom
worksbyfriday:fix-multipleOf-integer-float
Open

worksbyfriday wants to merge 1 commit into
python-jsonschema:mainfrom
worksbyfriday:fix-multipleOf-integer-float

Conversation

@worksbyfriday

Copy link
Copy Markdown

Summary

When multipleOf is an integer-valued float (e.g. 11.0), the validator uses float division, which loses precision for instances beyond 2**53. This causes false negatives: 9007199254740995 is a multiple of 11, but 9007199254740995 / 11.0 loses precision and the check fails.

The fix converts integer-valued floats to int before performing the divisibility check, using float.is_integer(). This ensures that multipleOf: 11.0 behaves identically to multipleOf: 11, per the JSON Schema spec which states that numbers with zero fractional parts are integers.

Non-integer floats (e.g. 0.5) are unaffected — the isinstance(dB, float) branch still handles them.

Fixes #1159.

When multipleOf is a float with an integer value (e.g. 11.0), convert
it to int before performing the check. This avoids floating-point
precision loss for instances beyond 2**53, where float division
produces incorrect results.

Per JSON Schema spec, numbers with zero fractional parts are integers.

Fixes python-jsonschema#1159
@Julian Julian added the Needs Test Upstream Issues that need to have a test added to https://github.com/json-schema-org/JSON-Schema-Test-Suite label Aug 1, 2026

This branch was previously deployed

1 inactive deployment
PyPI — 08a8c225 Deployed Mar 1, 2026 by worksbyfriday via packaging #4130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Test Upstream Issues that need to have a test added to https://github.com/json-schema-org/JSON-Schema-Test-Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Instance validates if multipleOf is an integer, but fails if it's a float

2 participants